#!/bin/bash
#This script was written by Matthew Vona of ARB to support the CarbLogger 
#project 6/6/2011 for Ubuntu 11.04 using network manager to connect via
#a port knocker using knockd to open 5900
usage()
{
echo "Proper usage is $0 <connection name>"
}

#USER CONFIGURATION:
#CON_NAME is the name of the connection you want to use.
CON_NAME=$1;
#USE OPTIONAL TO RUN COMMANDS AFTER CONNECTION IS RE-ESTABLISHED
#IN THIS CASE WE WANT TO UPDATE DYNAMIC DNS WITH OUT CURRENT IP
#OPTIONAL=""
kon=''
if [ $# != "1" ]; then
{
usage
exit 1
}
fi 
kon=`ps -fe | grep knockd | grep -v $0 | wc -l`
while [ $kon -lt 2 ]
do
	knockd -d -i $CON_NAME
	sleep 50
	kon=`ps -fe | grep knockd | grep -v $0 | wc -l`
done
#$OPTIONAL
exit